#coding:utf8

from itsdangerous import TimedJSONWebSignatureSerializer as Serializer,SignatureExpired,BadSignature
from mall import settings
def generic_verify_url(user_id,email):


    # url 含有用户信息

    #1. 创建序列化器
    serializer = Serializer(settings.SECRET_KEY,3600)
    #2. 组织数据
    data = {
        'id':user_id,
        'email':email
    }
    #3.加密
    token = serializer.dumps(data)

    return 'http://www.meiduo.site:8080/success_verify_email.html?token=' + token.decode()


def check_active_token(token):

    #1. 创建序列化器
    serializer = Serializer(settings.SECRET_KEY, 3600)
    #2. 通过loads方法进行解密 可能有异常
    try:
        result = serializer.loads(token)
        # {id:xx,email:xxx}
    except BadSignature:
        return None
    else:
        # 3.返回id
        return result.get('id')



